package com.sc.sc250601.cook.controller;



import com.sc.sc250601.cook.pojo.Notification;
import com.sc.sc250601.cook.pojo.Result;
import com.sc.sc250601.cook.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/notifications")
public class NotificationController {

    @Autowired
    private NotificationService notificationService;

    // 查询用户的历史通知--未读的
    @GetMapping
    public Result getNotifications(@RequestParam("userId") Long userId) {
        List<Notification> notifications = notificationService.getNotificationsByUserId(userId);

        return new Result(1,"查询成功",notifications);
    }

    // 标记单个通知为已读
    @PostMapping("/read")
    public Result markAsRead(@RequestParam("id") Long id) {
        notificationService.markAsRead(id);
        return new Result(1,"标记成功");
    }

    // 标记所有通知为已读
    @PostMapping("/readAll")
    public Result markAllAsRead(@RequestParam("userId") Long userId) {
        notificationService.markAllAsRead(userId);
        return new Result(1,"全部标记为已读");
    }

}
